//
//  LoginViewController.swift
//  Driver
//
//  Created by lantaiyuan on 2017/10/25.
//  Copyright © 2017年 youmy. All rights reserved.
//

import UIKit

class LoginViewController: UIViewController {
    
    @IBOutlet weak var mobileTF: YMUITextField!
    
    @IBOutlet weak var passwordTF: YMUITextField!
    
    @IBAction func loginAction(_ sender: YMUIButton) {
        
        if mobileTF.text == nil {
            print("mobile can't null")
            return
        }
        
        if passwordTF.text == nil {
            print("password can't null")
            return
        }
        
        YMNetworkManager.shared.login(userName: mobileTF.text ?? "", password: passwordTF.text ?? "") {[weak self] (respose, finished) in
            
            if !finished {
                return
            }
            
            guard let user = User_root.model(withJSON: respose ?? [:]) else {
                return
            }
            
            if user.success {
                user.obj?.savaUserAccount()
                
                self?.view.window?.rootViewController = UIStoryboard.init(name: "Home", bundle: nil).instantiateInitialViewController()
            }
        }
    }
    
    @IBAction func registerAction(_ sender: YMUIButton) {
        
    }
    
    @IBAction func forgetPasswordAction(_ sender: YMUIButton) {
    }
    
    override func viewDidLoad() {
        
        super.viewDidLoad()

    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        navigationController?.navigationBar.isHidden = true
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        navigationController?.navigationBar.isHidden = false
    }

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        self.view.endEditing(true)
    }

}
